home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 65.zip / BS1 part 65 / Math Visin v2.1 disk 1.adf / Arexx.WB / Animation / MakeZoom < prev    next >
Text File  |  1992-02-12  |  18KB  |  544 lines

  1. /* MakeZoom Do-all, Be-all Interactive Animation Maker  24-Apr-90 dh 
  2.  
  3.   This program attempts to automate the production of animations using 
  4. MathVision.  You can have the coordinates change over time for a 'zooming'
  5. effect, and/or change the variable (p).  Each frame is saved to disk after
  6. it is computed, and a script file may be written, to aid you in combining
  7. the files into an animation.  Pictures are spread across multiple disks
  8. as there is room, and the production process may be halted and restarted
  9. at will.
  10.  
  11. ========================== DESCRIPTIONS OF COMMANDS ======================
  12.  
  13. V - Vary You may choose to have the coordinates and/or the variable
  14.       P change from frame to frame.  If you choose to vary the
  15.       coordinates, you should also set the starting and ending
  16.       coordinates (C).  If you choose to vary the parameter, you
  17.       should also set the starting and ending values for the
  18.       parameter (P).  If the coordinates or parameter are not
  19.       being varied, they are ignored, and need not be set. 
  20.  
  21. C - Coords  The starting and ending coordinates may be changed.  You may
  22.       either enter them directly, or have the values copied from
  23.       MathVision.  Feel free to flip back to MathVision and load
  24.       a picture to get coordinates to copy.  It is assumed that
  25.       you are zooming in, that is, toward 'smaller' coordinates.
  26.  
  27. P - Parameter  The variable 'P' is varied from the starting to ending
  28.       values linearly, divided into Frames steps.  You should
  29.       use the variable 'P' in your function, as in
  30.       Mandel(x,y,x,y,100,P).
  31.  
  32. D - Filename   The filename tells where the plotted pictures should be
  33.       stored.  If you have a hard disk which can contain all
  34.       the pictures generated, enter something like
  35.       DH0:DRAWER/Pic.  If you are storing on diskettes, enter
  36.       something like ZOOM:Pic, so everything is in the root
  37.       directory.  If the disk is filled up, this program will
  38.       tack a number onto the volume name, starting with 1, and 
  39.       attempt to write to that, ie. ZOOM1:Pic.  It is good to
  40.       have a number of disks formatted and ready to go, with names
  41.       such as Zoom, Zoom1, Zoom2, Zoom3...
  42.  
  43. I - Instruction   Normally, this will be 'Plot'.  If you want to execute
  44.       a different type of plot, such as DivideAndConquer (in the
  45.       Mandelbrot hook), enter that command here.  More than
  46.       one command may be put here, separated by semicolons, but
  47.       only the first is retrieved from the Settings file.
  48.       This string is interpreted by ARexx, so make these valid
  49.       ARexx commands/instructions.
  50.  
  51. F - Frames  This specifies the number of pictures to be plotted, and
  52.       is also used to determine the amount of change between 
  53.       frames.  Larger numbers give longer, smoother animations.
  54.  
  55. N - Next Frame This is the number of the next picture to be plotted.  
  56.       If the production was interrupted (power interruption)
  57.       such that the settings were not saved, you may need to 
  58.       set this manually.  Normally, leave it alone.
  59.  
  60. G - Go!     Proceed with production, using all the parameters above.
  61.       You may stop production by clicking on a MathVision screen,
  62.       and pressing <Ctrl><Esc>.  Remember to use <Esc> too if you 
  63.       want the plotting to stop immediately.  
  64.  
  65. L - Load Settings  Load settings from file.  This is useful for resuming 
  66.       production after having used your Amiga for other
  67.       purposes (ie, Real Work.)
  68.  
  69. S - Save Settings  Save settings to file.  It is a good idea to save your
  70.       settings before you actually begin production, and each
  71.       time you interrupt production and quit this program.
  72.  
  73. W - Write Script  This creates a file containing the names of all pictures
  74.       plotted.  The program MakeAnim requires a script of this
  75.       type.
  76.  
  77. ============================== EXAMPLE OF USE ============================== 
  78.  
  79. Suppose I wanted to do a zoom of the Mandelbrot set, using 100 frames.
  80.  
  81. - Format 2 diskettes, with the names MZoom and MZoom1
  82. - Start MathVision running
  83. - Turn off Write Icons in the Project/Save menu. (saves space)
  84. - Load the Mandelbrot hook for MathVision
  85. - Start this program running
  86. - Set the coordinates.  I set the starting coordinates myself, since I 
  87.    want to start with the full Mandelbrot set.  I load my 'target'
  88.    picture  (the one I want the zoom to end with) into MathVision, and
  89.    get the ending coordinates from MathVision.
  90. - Make sure MathVision is set up with the right formula, scaling, colors, etc.
  91. - Set the filename.  I'll do this on floppies, with the name MZoom:M
  92. - Set the instruction.  I want to do a DivideAndConquer plot, so I put
  93.    that here.
  94. - Frames I set at 100.
  95. - Save Settings, on the MZoom disk, for future reference.
  96. - Insert the MZoom and MZoom1 disks in my drives.
  97. - hit Go
  98. - go to bed
  99.  
  100. Suppose that when I awoke, it had only finished through frame 69, and
  101. I needed to use my computer for other things during the day.
  102.  
  103. - Click on a MathVision screen
  104. - Press <Ctrl><Esc> and then <ESC>  (stop production)
  105. - Save settings and exit program
  106.  
  107. Later, I wanted to continue production.
  108.  
  109. - Start MathVision running
  110. - Turn off Write Icons in the Project/Save menu. (saves space)
  111. - Load the Mandelbrot hook for MathVision
  112. - Load the initial picture (MZoom:M0000, in this case)
  113. - Start this program
  114. - Load settings
  115. - Go
  116.  
  117. This time, the production finished.
  118.  
  119. - Save Settings (one never knows!)
  120. - Write Script file
  121. - exit this program
  122. - quit MathVision
  123. - Edit the script file, to allow for loops, special effects, etc.
  124. - Make the animation, using a program such as the PD makeanim.
  125.  
  126.  
  127. ============================================================================ */
  128.  
  129. ADDRESS "MathVision"
  130. OPTIONS RESULTS
  131. OPTIONS FAILAT 10
  132. NUMERIC DIGITS 14
  133. SIGNAL ON ERROR
  134.  
  135. Xmin0 = 0; XMax0 = 1
  136. Ymin0 = 0; YMax0 = 1
  137. Xmin1 = 0; XMax1 = 1
  138. Ymin1 = 0; YMax1 = 1
  139.  
  140. VaryCoords = 1;       VaryParameter = 0
  141. ParameterStart = 0;   ParameterEnd = 1
  142. Frames = 10;          NextFrame = 0
  143. Volume = "Zoom";      Path = "Pic";  Filename = Volume":"Path 
  144. DiskNumber = 0
  145. ArchiveFile = "Zoom:ZoomSettings"
  146. Instruction = "Plot"
  147. ElapsedTime = 0
  148. Complete = 0
  149.  
  150. DiskMargin = 45        /* panic when only this many K space left */
  151.  
  152. ClrScr = D2C(12)
  153. StopSign "F"
  154.  
  155. QuitZoom = 0
  156. DO WHILE (QuitZoom==0)
  157.   command = MENU()
  158.  
  159.   SELECT
  160.     WHEN command = 'F' THEN Frames = GetAns("Frames", Frames )
  161.     WHEN command = 'L' THEN CALL LoadSettings
  162.     WHEN command = 'S' THEN CALL SaveSettings
  163.     WHEN command = 'W' THEN CALL WriteScript
  164.     WHEN command = 'G' THEN CALL Zoom
  165.     WHEN command = 'N' THEN
  166.      DO
  167.        NextFrame = GetAns("Next Frame",NextFrame)
  168.        if (NextFrame==0) THEN
  169.          DO
  170.            ElapsedTime = 0
  171.            Complete = 0
  172.          END
  173.      END
  174.     WHEN command = 'I' THEN 
  175.       DO
  176.         Say "Enter Plotting instructions on the line below:"
  177.         OPTIONS PROMPT ""
  178.         PARSE PULL I
  179.         if (Length(i)~=0)
  180.           THEN Instruction = i
  181.       END
  182.     WHEN command = 'X' THEN 
  183.       DO
  184.         QuitZoom = GetBoo("Do you really want to exit?",QuitZoom)
  185.         if (QuitZoom~=0) THEN
  186.           DO
  187.             ans = GetBoo("Save Settings before exit?", 1)
  188.             if (ans~=0) THEN CALL SaveSettings
  189.           END
  190.       END
  191.     WHEN command = 'V' THEN
  192.       DO 
  193.         VaryCoords = GetBoo("Vary Coordinates", VaryCoords)
  194.         VaryParameter = GetBoo("Vary Parameter", VaryParameter)
  195.       END
  196.     WHEN command = 'P' THEN
  197.       DO
  198.         ParameterStart = GetAns("Starting Parameter", ParameterStart )
  199.         ParameterEnd   = GetAns("Ending Parameter", ParameterEnd )
  200.       END
  201.     WHEN command = 'C' THEN
  202.       DO 
  203.         if (GetBoo("Change Starting Coordinates", 0)~=0) THEN
  204.           DO
  205.             if (GetBoo("Get Coordinates from MathVision",0)~=0) THEN
  206.               DO
  207.                 Get XMin;  Xmin0 = RESULT
  208.                 Get XMax;  XMax0 = RESULT
  209.                 Get YMin;  Ymin0 = RESULT
  210.                 Get YMax;  YMax0 = RESULT
  211.               END
  212.             ELSE
  213.               DO
  214.                 XMin0 = GetAns("XMin",XMin0)
  215.                 XMax0 = GetAns("XMax",XMax0)
  216.                 YMin0 = GetAns("YMin",YMin0)
  217.                 YMax0 = GetAns("YMax",YMax0)
  218.               END
  219.           END
  220.         if (GetBoo("Change Ending Coordinates", 0)~=0) THEN
  221.           DO
  222.             if (GetBoo("Get Coordinates from MathVision",0)~=0) THEN
  223.               DO
  224.                 Get XMin;  Xmin1 = RESULT
  225.                 Get XMax;  XMax1 = RESULT
  226.                 Get YMin;  Ymin1 = RESULT
  227.                 Get YMax;  YMax1 = RESULT
  228.               END
  229.             ELSE
  230.               DO
  231.                 XMin1 = GetAns("XMin",XMin1)
  232.                 XMax1 = GetAns("XMax",XMax1)
  233.                 YMin1 = GetAns("YMin",YMin1)
  234.                 YMax1 = GetAns("YMax",YMax1)
  235.               END
  236.           END
  237.       END
  238.     WHEN command = 'D' THEN
  239.       DO FOREVER
  240.         Filename = GetAns("Filename", FileName )
  241.         i = index(filename,":")
  242.         if (i~=0)
  243.           THEN
  244.             DO Volume = Left(filename,i-1)
  245.                Path = SubStr(filename,i+1)
  246.                BREAK
  247.             END
  248.           ELSE
  249.             ans = SayError("Please specify a volume and path, ie ZOOM:Pic")
  250.         if (i~=0) THEN BREAK
  251.       END
  252.     OTHERWISE;
  253.   END /*select*/
  254. END
  255.  
  256. EXIT
  257.  
  258. /*================================== MENU ================================= */
  259.  
  260. MENU:
  261.   SAY ClrScr "---------------- MakeZoom Menu -----------------"
  262.   SAY 
  263.   SAY "V - Vary:  Coordinates ("Boo2Text(VaryCoords)")"
  264.   SAY "           Parameter ("Boo2Text(VaryParameter)")" 
  265.   if (VaryCoords~=0)
  266.   THEN
  267.     DO
  268.       SAY "C - Coords Start: Xmin " XMin0 " Xmax " XMax0
  269.       SAY "                  Ymin " YMin0 " Ymax " YMax0
  270.       SAY "             End: Xmin " XMin1 " Xmax " XMax1
  271.       SAY "                  Ymin " YMin1 " Ymax " YMax1
  272.     END
  273.   if (VaryParameter~=0)
  274.   THEN SAY "P - Parameter: ("ParameterStart") to ("ParameterEnd")"
  275.   SAY "D - Filename ("FileName")"
  276.   SAY "I - Instruction ("Instruction")"
  277.   SAY Overlay("L - Load Settings", "F - Frames ("Frames")",35)
  278.   SAY Overlay("S - Save Settings", "N - Next Frame ("NextFrame")",35)
  279.   SAY Overlay("W - Write Script", "G - Go!",35)
  280.   SAY "X - Exit"
  281.  
  282.   OPTIONS PROMPT "--------------> "
  283.   PULL Command
  284.  
  285.   RETURN command
  286.  
  287. /*================================== ZOOM ================================= */
  288.  
  289. Zoom:
  290.  
  291.   IF (VaryCoords~=0) THEN
  292.   DO
  293.     XCenter0 = (XMin0+XMax0)/2
  294.     YCenter0 = (YMin0+YMax0)/2
  295.     XWidth0 = (XMax0-XMin0)
  296.     YWidth0 = (YMax0-YMin0)
  297.     XCenter1 = (XMin1+XMax1)/2
  298.     YCenter1 = (YMin1+YMax1)/2
  299.     XWidth1 = (XMax1-XMin1)
  300.     YWidth1 = (YMax1-YMin1)
  301.     xfactor = xwidth1/xwidth0
  302.     yfactor = ywidth1/ywidth0
  303.   END
  304.  
  305.   IF (VaryParameter~=0) THEN
  306.   DO
  307.     ParameterWidth = ParameterEnd - ParameterStart
  308.   END
  309.  
  310.   DO PictureNumber = NextFrame TO Frames-1      /* for each picture*/
  311.  
  312.     Get DiskSpace MakeDiskName(Volume,DiskNumber)  /* get disk with room */
  313.     DO WHILE (1*RESULT < 1*DiskMargin)
  314.       DiskNumber = DiskNumber+1
  315.       SAY "Please insert an empty diskette named "MakeDiskName(Volume,DiskNumber)
  316.       Get DiskSpace MakeDiskName(Volume,DiskNumber)
  317.     END
  318.  
  319.     ok = Time('Reset')
  320.  
  321.     fn.PictureNumber = MakeDiskName(Volume,DiskNumber)Path||Right(PictureNumber,4,"0")
  322.     SAY "Plotting: "fn.PictureNumber
  323.  
  324.     mult = (PictureNumber) / (Frames-1)      /* 0..1 */
  325.  
  326.     IF (VaryParameter~=0) THEN
  327.     DO
  328.       Parameter = mult*ParameterWidth+ParameterStart
  329.       P Parameter
  330.     END
  331.  
  332.     IF (VaryCoords~=0) THEN
  333.     DO
  334.       if (PictureNumber == 0) THEN  /* avoid ARexx bug with -0 */
  335.       DO 
  336.         XMin Xcenter0-XWidth0/2 
  337.         XMax Xcenter0+XWidth0/2 
  338.         YMin Ycenter0-YWidth0/2 
  339.         YMax Ycenter0+YWidth0/2 
  340.       END
  341.       ELSE
  342.       DO
  343.         xmag = power(xfactor,mult)
  344.         ymag = power(yfactor,mult)
  345.         xwidth = xwidth0*xmag
  346.         ywidth = ywidth0*ymag
  347.         xcenter = xcenter0+((xcenter1-xcenter0)*(xmag-1) / (xfactor-1) )
  348.         ycenter = ycenter0+((ycenter1-ycenter0)*(ymag-1) / (yfactor-1) )
  349.  
  350.         Xmin xcenter-xwidth/2    /* plug in the new values */
  351.         Xmax xcenter+xwidth/2
  352.         Ymin ycenter-ywidth/2
  353.         Ymax ycenter+ywidth/2
  354.       END
  355.     END
  356.  
  357.     Pathname fn.PictureNumber    
  358.     if ( (Complete~=0) & (EXISTS(fn.PictureNumber)~=0) ) THEN
  359.     DO 
  360.       OverPlot T
  361.       LoadPicture
  362.       'Complete' Complete
  363.     END
  364.  
  365.     INTERPRET Instruction     /* do the appropriate plot */
  366.  
  367.     Get 'Complete'
  368.     Complete = RESULT
  369.  
  370.     SAY D2c(11)"Saving:  "
  371.     if ((PictureNumber==0) | (PictureNumber==Frames-1) )
  372.       THEN SavePictureAndFormula
  373.       ELSE SavePicture
  374.     if (Complete==0)
  375.       THEN NextFrame = PictureNumber+1
  376.  
  377.     Get StopSign
  378.     IF Result = "T" 
  379.       THEN BREAK
  380.  
  381.   ElapsedTime = ElapsedTime + Time("Elapsed")
  382.   Say ConvertTime(ElapsedTime/(PictureNumber+1) * (Frames-1-PictureNumber))" to go."
  383.  
  384.   END /* do */
  385.   StopSign "F"
  386.  
  387.   return(0)
  388. RETURN
  389.   
  390. /*---------------------------------- SaveSettings ------------------------- */
  391. /* archive state of the animation program to disk */
  392. SaveSettings:
  393.  
  394.   ArchiveFile = GetAns("Save settings to", ArchiveFile)
  395.   IF (~OPEN(arch, ArchiveFile,'Write'))
  396.   THEN DO ok = SayError("Can't open file '"ArchiveFile"'"); Return(0); END
  397.  
  398.   ok = WRITELN(Arch,"XMin0="Xmin0)
  399.   ok = WRITELN(Arch,"XMax0="Xmax0)
  400.   ok = WRITELN(Arch,"YMin0="Ymin0)
  401.   ok = WRITELN(Arch,"YMax0="Ymax0)
  402.   ok = WRITELN(Arch,"XMin1="Xmin1)
  403.   ok = WRITELN(Arch,"XMax1="Xmax1)
  404.   ok = WRITELN(Arch,"YMin1="Ymin1)
  405.   ok = WRITELN(Arch,"YMax1="Ymax1)
  406.   ok = WRITELN(Arch,"VaryCoords="VaryCoords )
  407.   ok = WRITELN(Arch,"VaryParameter="VaryParameter )
  408.   ok = WRITELN(Arch,"ParameterStart="ParameterStart )
  409.   ok = WRITELN(Arch,"ParameterEnd="ParameterEnd )
  410.   ok = WRITELN(Arch,"Frames="Frames )
  411.   ok = WRITELN(Arch,"DiskNumber="DiskNumber )
  412.   ok = WRITELN(Arch,"Volume='"Volume"'" )
  413.   ok = WRITELN(Arch,"Path='"Path"'" )
  414.   ok = WRITELN(Arch,"NextFrame="NextFrame )
  415.   ok = WRITELN(Arch,"Instruction='"Instruction"'" )
  416.   ok = WRITELN(Arch,"ElapsedTime="ElapsedTime )
  417.   ok = WRITELN(Arch,"Complete="Complete )
  418.  
  419.   DO i = 0 to NextFrame-1
  420.     ok = WRITELN(Arch,"FN."i"='"fn.i"'")
  421.   END
  422.   ok = CLOSE(Arch)
  423.   RETURN(0)
  424. END
  425.  
  426. /*---------------------------------- LoadSettings ------------------------- */
  427. /* get archived state of the animation program from disk */
  428. LoadSettings:
  429.  
  430.   ArchiveFile = GetAns("Load settings from", ArchiveFile)
  431.   IF (~OPEN(arch, ArchiveFile,'Read'))
  432.   THEN DO ok = SayError("Can't open file '"ArchiveFile"'"); Return(0); END
  433.  
  434.   DO WHILE ~EOF(Arch)
  435.     INTERPRET READLN(Arch)    /* ARexx is SO SWEET! */
  436.   END
  437.  
  438.   Filename = Volume":"Path
  439.   ok = CLOSE(Arch)
  440.   RETURN(0)
  441. END
  442.  
  443. /*---------------------------------- WriteScript --------------------------- */
  444. WriteScript:
  445.   ArchiveFile = GetAns("Save Script To", Volume":"Path"Script")
  446.   IF (~OPEN(arch, ArchiveFile,'Write'))
  447.   THEN DO ok = SayError("Can't open file '"ArchiveFile"'"); Return(0); END
  448.  
  449.   DO i = 0 to NextFrame-1
  450.     ok = WRITELN(Arch,FN.i)
  451.   END
  452.  
  453.   ok = CLOSE(Arch)
  454.   RETURN(0)
  455. /* --------------------------------- GetAns -------------------------------- */
  456. /* result = GetAns( prompt, default) */
  457. /* prompt for input, displaying default. Accept one item. If only <return> */
  458. /* was pressed, return the default answer */
  459.  
  460. GetAns: PROCEDURE
  461.   parse arg prompter, default
  462.   Options Prompt Prompter "(" Default "): "
  463.   parse pull response
  464.   if (response = "") THEN response = default;
  465.   return(response)
  466.  
  467. /*------------------------------- GetBoo ----------------------------------- */
  468. /* result = GetBoo( prompt, default) */
  469. /* prompt for boolean input, where 0 means false an <>0 means true */
  470. /* parse the user input appropriately */
  471. GetBoo: PROCEDURE
  472.   parse arg prompter, default
  473.   ans = GetAns( prompter, Boo2Text(default) )
  474.   if (ans==Boo2Text(default))
  475.     THEN return(default);  /* pressed return! */
  476.   ans = left(ans,1,)
  477.   ret = 1
  478.   if(Index("0nN",ans)~=0)
  479.     THEN ret = 0;
  480.   return(ret)
  481.  
  482. /*----------------------------- Boo2Text ----------------------------------- */
  483. /* result = Boo2Text( bnumber ) */
  484. Boo2text:
  485.   parse arg bnumber
  486.   if (bnumber==0)
  487.     THEN return("No")
  488.     ELSE return("Yes")
  489.  
  490. /*------------------------------ MakeDiskName ------------------------------ */
  491. MakeDiskName: PROCEDURE
  492.   parse arg volume, number
  493.   if (number==0)
  494.     THEN return(Volume)":"
  495.     ELSE return(volume||Number":")
  496.  
  497. /*------------------------------- SayError --------------------------------- */
  498. /* display error message and wait for action */
  499. SayError: PROCEDURE
  500.   parse arg prompter
  501.   say prompter
  502.   Options Prompt "Press <RETURN> to continue: "
  503.   pull response
  504.   return( 0 )
  505.  
  506. /*--------------------------------- Plural --------------------------------- */
  507. /* make plural of words */
  508. Plural: PROCEDURE
  509.   parse arg number
  510.   if (number~=1)
  511.     THEN return('s')
  512.     ELSE return('')
  513.  
  514. /*-------------------------------- ConvertTime ----------------------------- */
  515. /* convert seconds to go into hours, days, min, etc */
  516. ConvertTime: PROCEDURE
  517.   parse arg secs
  518.  
  519.   Days  = secs  % (60*60*24)
  520.   secs  = secs // (60*60*24)
  521.   Hours = secs  % (60*60)
  522.   secs  = secs // (60*60)
  523.   Mins  = secs  % (60)
  524.   secs  = secs // (60)
  525.   secs  = secs %  (1)
  526.  
  527.   if (Days ~=0) THEN return(Days" day"Plural(Days)" and "Hours" hour"Plural(Hours))
  528.   if (Hours~=0) THEN return(Hours" hour"Plural(Hours)" and "Mins" minute"Plural(Mins))  
  529.   if (Mins ~=0) THEN return(Mins" minute"Plural(Mins)" and "Secs" second"Plural(Secs))
  530.   return(Secs" second"Plural(Secs))
  531.  
  532. POWER:         /* number to power */
  533.   arg base, pow
  534.   Get Eval base"^"pow   /* kick MathVision to evaluate this */
  535.   return(result)
  536.  
  537. ERROR:         /* Error Diagnostic for return codes */
  538.   Get Diagnosis RC
  539.   SAY RESULT" on line "SIGL
  540.   DO i = 1 to 1000
  541.   END
  542.   EXIT
  543.  
  544.